﻿package com.curlyben.utils {
	
	/**
	* ...
	* @author Default
	*/
	public class Convert {
		
		public function Convert() {
			
		}
		
		public static function ToBinary(value:int):String {
			var out:String = "";
			out += value & 0x80000000 ? "1" : "0";
			out += value & 0x40000000 ? "1" : "0";
			out += value & 0x20000000 ? "1" : "0";
			out += value & 0x10000000 ? "1" : "0";
			out += value & 0x08000000 ? "1" : "0";
			out += value & 0x04000000 ? "1" : "0";
			out += value & 0x02000000 ? "1" : "0";
			out += value & 0x01000000 ? "1" : "0";
			
			out += value & 0x00800000 ? "1" : "0";
			out += value & 0x00400000 ? "1" : "0";
			out += value & 0x00200000 ? "1" : "0";
			out += value & 0x00100000 ? "1" : "0";
			out += value & 0x00080000 ? "1" : "0";
			out += value & 0x00040000 ? "1" : "0";
			out += value & 0x00020000 ? "1" : "0";
			out += value & 0x00010000 ? "1" : "0";
			
			out += value & 0x00008000 ? "1" : "0";
			out += value & 0x00004000 ? "1" : "0";
			out += value & 0x00002000 ? "1" : "0";
			out += value & 0x00001000 ? "1" : "0";
			out += value & 0x00000800 ? "1" : "0";
			out += value & 0x00000400 ? "1" : "0";
			out += value & 0x00000200 ? "1" : "0";
			out += value & 0x00000100 ? "1" : "0";
			
			out += value & 0x00000080 ? "1" : "0";
			out += value & 0x00000040 ? "1" : "0";
			out += value & 0x00000020 ? "1" : "0";
			out += value & 0x00000010 ? "1" : "0";
			out += value & 0x00000008 ? "1" : "0";
			out += value & 0x00000004 ? "1" : "0";
			out += value & 0x00000002 ? "1" : "0";
			out += value & 0x00000001 ? "1" : "0";
			return out;
		}
		
		public static function FromBinary(value:String):uint {
			value = Strings.PadLeft(value, "0", 32);
			var split	:Array	= value.split("");
			var out		:uint = 0x00000000;
			var pattern	:uint = 0x00000001;
			while (split.length > 0) {
				if (split.pop() == "1") {
					out |= pattern;
				}
				pattern <<= 1;
			}
			return out;
		}
	}
	
}